﻿@model Jb.Web.ViewModels.UtilityModels.ListConfig
@using Jb.Common.Extensions;
@using Jb.Web.Utility;
@using Jb.Common.DB;
@using Jb.Web.ViewModels;

@{    
	String pageTitle = "Job Applications";
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    JobAppListType _ListType = JobAppListType.All;
    if (String.Compare(WebUtil.GetQueryStringValue("type"), "S", true) == 0){
        _ListType = JobAppListType.ShortListed;
    }
    else if(String.Compare(WebUtil.GetQueryStringValue("type"), "I", true) == 0){
        _ListType = JobAppListType.CalledForInterview;
    }
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = EmployerMenu.ManageApplications;
    ViewData[AppConstants.ViewDataKeys.LIST_TYPE] = _ListType;
    Jb.Web.ViewModels.JobViewModel _Job = ViewData[AppConstants.ViewDataKeys.SECONDARY_MODEL] as Jb.Web.ViewModels.JobViewModel;
    Model.Pager.UrlFormat = "/Private/JobApplication/List/" + _Job == null ? "0" : _Job.ID.ToString() + "?type=" + WebUtil.GetQueryStringValue("type") + "&pageNo={0}";
    
    Jb.Web.ViewModels.InterviewRequestViewModel _InterviewRequest = new Jb.Web.ViewModels.InterviewRequestViewModel();
    _InterviewRequest.InterviewMinute = _InterviewRequest.InterviewHour = -1;    
}
<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>
        Job Applications for: @(_Job == null ? String.Empty : _Job.Title )
    </div>
</div>
<div class="jb-page-content">
    @if (_Job == null)
    {
        @Html.WarningMessageBox("Sorry! the requested job was not found.")
    }
    else {
        String _ExpireMessage = _Job.EndDate.ToDateTime(ConfigReader.CSharpCalendarDateFormat) >= DateTime.Now ? "Expires On " : "Expired On ";
        <div>
            <div class="jb-group-title">Short Job Information</div>
            <h2><small><a href="@Url.JobDetailsUrl(_Job.ID, _Job.Url)" target="_blank">@_Job.Title</a></small></h2>
            <div class="jb-label-hint">
                Published On @Html.FormatData(_Job.PostDate.ToDateTime(ConfigReader.CSharpCalendarDateFormat)) and @_ExpireMessage @Html.FormatData(_Job.EndDate.ToDateTime(ConfigReader.CSharpCalendarDateFormat))
            </div>
            <div class="para">
                @Html.Raw(Html.FormatData(WebUtil.GetFormattedJobDescription(_Job.Description)))
            </div>
        </div>
        
        <div class="jb-group-title">Job Application List            
            <div class="btn-group pull-right" style="font-weight:normal;">
                <a href="/Private/JobApplication/List/@(_Job.ID)" class="btn btn-mini @(_ListType == JobAppListType.All ? "btn-primary" : String.Empty)"><i class="icon-list-alt @(_ListType == JobAppListType.All ? "icon-white" : String.Empty)"></i> All</a>
                <a href="/Private/JobApplication/List/@(_Job.ID)?type=S" class="btn btn-mini @(_ListType == JobAppListType.ShortListed ? "btn-primary" : String.Empty)"><i class="icon-filter @(_ListType == JobAppListType.ShortListed ? "icon-white" : String.Empty)"></i> Short Listed</a>
                <a href="/Private/JobApplication/List/@(_Job.ID)?type=I" class="btn btn-mini @(_ListType == JobAppListType.CalledForInterview ? "btn-primary" : String.Empty)"><i class="icon-star-empty @(_ListType == JobAppListType.CalledForInterview ? "icon-white" : String.Empty)"></i> Called for Interview</a>
            </div>
            <div class="clearfix"></div>
        </div>
        
        @Html.Partial("_JobApplicationList", Model.DataSource)
        if (Model.Pager != null) {
            @Html.Partial("_Pager", Model.Pager)
        }
    }    
</div>

@*Modal Popup (Job Application) Section Starts*@
<div id="divSearchTipsDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="divPhotoEditModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
        <h4 id="myModalLabel">Job Application</h4>
    </div>
    <div class="modal-body jb-inline-label">            
        <div id="divModalMesssage"></div>
    </div>
    <div class="modal-footer">        
        <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i> Close</button>
    </div>
</div>
@*Modal Popup (Job Application) Section Ends*@

@*Modal Popup (Interview Request) Section Starts*@
<div id="divInterviewDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="divPhotoEditModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
        <h4>Invite for Interview</h4>
    </div>
    <div class="modal-body">            
        <div id="divInterviewModalBody">
            <div id="divInterviewRequestResult"></div>
            @Html.Partial("_InterviewRequest", _InterviewRequest)
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" onclick="SendInterviewRequest();"><i class="icon-thumbs-up icon-white"></i> Send Invitation</button>
        <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i> Close</button>
    </div>
</div>
@*Modal Popup (Interview Request) Section Ends*@

@section PageHeadSection
{
    <link href="@Url.Content("~/Content/themes/jb-ui/jquery.ui.all.css")" rel="stylesheet" type="text/css" />    
}

@section JavaScriptPlaceHolder
{
@Html.JavaScript("jquery.validate.min.js", Url)
@Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
@Html.JavaScript("jquery-ui-1.8.11.min.js", Url)
@Html.Partial("_DatePicker")
<script language="javascript" type="text/javascript">
    function ShowApplication(applicationID) {
        var divID = 'divCoverLetter_' + applicationID;        
        $('#divModalMesssage').html($('#' + divID).html());
        $('#divSearchTipsDialog').modal({ show: true });

        Ajax('/Private/JobApplication/UpdateReadStatus', 'ApplicationID=' + applicationID, function (result) {
            var status = parseInt(result);
            if (status == 1) {
                $('#' + divID).parent().find('.label-warning').slideUp('slow');
            }
        });
    }
    function ShortList(applicationID, anchor) {
        if ($(anchor).hasClass('disabled')) return;
        ShowLoadingAnimation(false);
        Ajax('/Private/JobApplication/ShortListApplication', 'ApplicationID=' + applicationID, function (result) {
            HideLoadingAnimation();
            var status = parseInt(result);
            if (status == 1) {
                $(anchor).addClass('disabled').html('<i class="icon-filter"></i> Short Listed');
            }
        });
    }
    var _ApplicationID = 0;
    var _InterviewAnchor = null;
    function ShowInterviewRequestDialog(applicationID, anchor) {
        if ($(anchor).hasClass('disabled')) return;
        _ApplicationID = applicationID;
        _InterviewAnchor = anchor;
        $('#divInterviewDialog').modal({ show: true });
        ResetInterviewRequestForm();
    }
    function SendInterviewRequest() {
        if ($('#frmInterviewRequest').valid()) {
            ShowLoadingAnimation(false);
            var data = 'id=' + $('#ID').val() + '&applicationID=' + _ApplicationID + ' &date=' + $('#InvitationDate').val() + '&hour=' + $('#InterviewHour').val() + '&minute=' + $('#InterviewMinute').val() + '&message=' + encodeURIComponent($('#Message').val());
            Ajax('/Private/JobApplication/SendInterviewRequest', data, function (result) {
                HideLoadingAnimation();
                var resultParts = result.split(':');
                var status = parseInt(resultParts[0]);
                var html = '';
                if (status == 1) {
                    html = SuccessMessageBox('Interview Request sent successfully.');
                    $(_InterviewAnchor).addClass('disabled').html('<i class="icon-star-empty"></i> Called for Interview')                    
                }
                else if (status == -4)
                    html = WarningMessageBox('Sorry! Something went wrong and we could not sent the Interview Request email. But it is saved in your account and you can try to resend it after some time.');
                else
                    html = WarningMessageBox('Sorry! Invalid Interview Request.');
                $('#hdnInterviewID_' + _ApplicationID).val(resultParts[1]);
                $('#divInterviewRequestResult').html(html);
            });
        }
    }
    function ResetInterviewRequestForm() {        
        if (_ApplicationID != parseInt($('#ApplicationID').val())) {
            $('#divInterviewRequestResult').html('');
            $('#ApplicationID').val(_ApplicationID);
            $('#InvitationDate').val('');
            $('#InterviewHour').val(-1);
            $('#InterviewMinute').val(-1);
            $('#Message').val('');
            var interviewID = parseInt($('#hdnInterviewID_' + _ApplicationID).val());
            $('#ID').val(interviewID);
            if (interviewID > 0) {
                ShowLoadingAnimation(false);
                Ajax('/Private/JobApplication/GetInterviewRequest', 'ID=' + interviewID, function (result) {
                    HideLoadingAnimation();
                    if (result.length > 0) {
                        var interview = eval('(' + result + ')');
                        $('#InvitationDate').val(interview.InvitationDate);
                        $('#InterviewHour').val(interview.InterviewHour);
                        $('#InterviewMinute').val(interview.InterviewMinute);
                        $('#Message').val(interview.Message == 'N/A' ? '' : interview.Message);
                    }
                });
            }
        }
    }
</script>
}
    


